当编译和运行.NET应用程序时发生在底层的细节

您所在的位置:网站首页 mplayer slave模式命令 当编译和运行.NET应用程序时发生在底层的细节

当编译和运行.NET应用程序时发生在底层的细节

2023-04-05 02:03| 来源: 网络整理| 查看: 265

          1 、程序员使用任意的一种 .NET 语言编写源代码。

        2、源代码被编译成标准的PE文件。

        3、.NET编译器生成一个包含包含标准PE头(PE header)的EXE文件,其中MSIL代码和清单(mainfest)做为EXE文件的只读部分。(到目前为止,术语(term)清单是能充分理解的。它所引用的信息保存在NET二进制代码中。清单描述了二进制代码的内容和运行时的需求。【For now, it’s enough to understand that the term manifest refers to the information stored in a .NET binary that describes that binary’s contents and runtime requirements.】

        4、当编译器在创建输出文件的同时,也从 .NET运行时中引入函数_CoreExeMain。这是重要部分。

        5、当用户运行程序时,操作系统加载PE以及相关的DLLs文件,诸如_CorExeMain函数(mscoree.dll)。

        6、操作系统加载PE之后,跳转到.NET编译器指定的入口地址。Windows按照相同的方式加载并运行其他PE。 7、因为操作系统能明确地(obviously)运行MSIL代码,从入口点跳转到mscoree.dll只消耗很短暂的时间。(Because the operating system obviously can’t execute the MSIL code, the entry point is just a small stub that jumps to the _CorExeMain function in mscoree.dll.)

       8、_CoreExeMain函数负责启动运行编译器放置在PE中MSIL代码。

       9 、 MSIL 代码只所以不能直接运行,是因为 MSIL 没有采用机器运行格式( machine-excutable format )。因此,通用语言运行时( the common language runtime ) 采用 just-in-time compiler ( JITter )把 MSIL 编译为本地 CPU 指令。 JIT 编译技术以方法的形式在程序中调用。编译后的可执行代码被缓存在机器中,直到部分源代码改变时,才重新编译。( MSIL code can ’ t be executed directly because it ’ s not in a machine-executable format. Therefore, the common language runtime compiles the MSIL — by using a just-in-time compiler (or JITter) — into native CPU instructions as it processes the MSIL. JIT compiling occurs only as methods in the program are called. The compiled executable code is cached on the machine and recompiled only if there ’ s some change to the source code. )

       上述内容的英文资料来源《Inside C#》(Sencond Edition eBook)         因本人的英语不好,翻译存在不足之处,请大家多多指点。谢谢!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3